001 /*
002 * Copyright (c) 2005 Stephen J. McConnell
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.component;
020
021 import java.io.IOException;
022 import java.net.URI;
023
024 /**
025 * General exception thrown by a control.
026 *
027 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
028 * @version 1.0.1
029 */
030 public class ControlException extends IOException
031 {
032 /**
033 * Serial version identifier.
034 */
035 static final long serialVersionUID = 1L;
036
037 private final URI m_uri;
038
039 /**
040 * Creation of a new <tt>ControlException</tt>.
041 * @param uri the part controller uri
042 * @param message the exception message
043 */
044 public ControlException( URI uri, String message )
045 {
046 this( uri, message, null );
047 }
048
049 /**
050 * Creation of a new <tt>ContextException</tt>.
051 * @param uri the part controller uri
052 * @param message the exception message
053 * @param cause the causal exception
054 */
055 public ControlException( URI uri, String message, Throwable cause )
056 {
057 super( message );
058 super.initCause( cause );
059 m_uri = uri;
060 }
061
062 /**
063 * Return the controller uri.
064 * @return the uri identifying the controller that raised the exception
065 */
066 public URI getControllerURI()
067 {
068 return m_uri;
069 }
070
071 /**
072 * Iterates through exceptiion to locate the root causal exception.
073 * @return the root exception (possibly null)
074 */
075 public Throwable getRootCause()
076 {
077 Throwable cause = getCause();
078 if( null == cause )
079 {
080 return null;
081 }
082 else
083 {
084 while( true )
085 {
086 if( null == cause.getCause() )
087 {
088 return cause;
089 }
090 else
091 {
092 cause = cause.getCause();
093 }
094 }
095 }
096 }
097 }
098